<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    div{
      position: relative;
      width: 300px;
      height: 35px;
      border-bottom: 1px solid red;
      overflow: hidden;
      margin: 100px auto;
    }
    input{
      display: block;
      border: 0;
      outline: none;
      width: 100%;
      height: 100%;
    }
    img{
      width: 24px;
      height: 24px;
      position: absolute;
      top: 5px;
      right: 5px;
    }
  </style>
</head>
<body>
  <div>
    <input type="text" id="box">
    <img src="./images/open.png" alt="">
  </div>

  <script>
    var input = document.querySelector('input')
    var img = document.querySelector('img')

    var status = '睁眼'  // 闭眼

    img.onclick = function() {
      if( status === '睁眼' ) {
        this.src = './images/close.png'
        input.type = 'password'
        status = '闭眼'
      } else {
        this.src = './images/open.png'
        input.type = 'text'
        status = '睁眼'
      }
    }
  </script>
</body>
</html>